package elitech.vietnam.weatherfashion;

import java.util.ArrayList;
import java.util.List;

import android.app.Application;
import android.content.IntentFilter;
import android.util.DisplayMetrics;
import elitech.vietnam.weatherfashion.badge.BadgeHelper;
import elitech.vietnam.weatherfashion.config.Utils;
import elitech.vietnam.weatherfashion.dto.FriendDTO;
import elitech.vietnam.weatherfashion.dto.Notification;
import elitech.vietnam.weatherfashion.dto.PostDTO;
import elitech.vietnam.weatherfashion.notification.GCMBroadcastReceiver;

public class WFApplication extends Application {
	
	private static WFApplication mInstance;
	private int mWidth = 480;
	private int mHeight = 800;
	
	public List<PostDTO> todayData;
	public List<List<PostDTO>> weeklyData;
	public List<PostDTO> stylerAllData;
	public List<PostDTO> stylerFriendData;
	public List<PostDTO> selfData;
	public List<FriendDTO> userFriends;
	
	public List<Notification> mListNoti = new ArrayList<Notification>();
	public List<Notification> mList = new ArrayList<Notification>();
	
	public BadgeHelper mBadge;
	
	private String appDataDir;
	
	private GCMBroadcastReceiver mReceiver;

	@Override
	public void onCreate() {
		super.onCreate();
		mInstance = this;
		initGlobalData();
	}
	
	@Override
	public void onLowMemory() {
		Utils.Log("Low Memory..");
		super.onLowMemory();
		System.gc();
	}
	
	public static WFApplication getInstance() {
		return mInstance;
	}
	
	private void initGlobalData() {
		
		appDataDir = getApplicationInfo().dataDir;
		
		DisplayMetrics display = getResources().getDisplayMetrics();
		mWidth = display.widthPixels;
		mHeight = display.heightPixels;
		
		weeklyData = new ArrayList<List<PostDTO>>();
		weeklyData.add(null);
		weeklyData.add(null);
		weeklyData.add(null);
		weeklyData.add(null);
		weeklyData.add(null);
		
//		File cacheDir = StorageUtils.getCacheDirectory(context);
//		AppUtils.Log(cacheDir.getAbsolutePath());
//		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
//				.denyCacheImageMultipleSizesInMemory()
//				.threadPoolSize(1)
//				.threadPriority(Thread.NORM_PRIORITY - 2)
//				.memoryCache(new WeakMemoryCache())
//				.defaultDisplayImageOptions(
//						new DisplayImageOptions.Builder()
//						.displayer(new FadeInBitmapDisplayer(200))
//						.cacheInMemory(false)
//						.cacheOnDisc(true)
//						.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
//						.bitmapConfig(Bitmap.Config.RGB_565)
//						.showImageForEmptyUri(R.drawable.loading_time)
//						.showImageOnFail(R.drawable.loading_time)
//						// .showStubImage(R.drawable.loading_time)
//						.build())
//				.discCacheFileNameGenerator(new Md5FileNameGenerator())
//				.discCache(new UnlimitedDiscCache(cacheDir))
//				.writeDebugLogs()
//				.build();
//		// Initialize ImageLoader with configuration.
//		ImageLoader.getInstance().init(config);

	}
	
	public String getDataDir() {
		return appDataDir;
	}
	
	public void startGCMNotification() {
		if (mReceiver == null) {
			mReceiver = new GCMBroadcastReceiver();
			IntentFilter filter = new IntentFilter("com.google.android.c2dm.intent.RECEIVE");
			filter.addCategory("elitech.vietnam.weatherfashion");
			registerReceiver(mReceiver, filter, "com.google.android.c2dm.permission.SEND", null);
		}
	}
	
	public void stopGCMNotification() {
		if (mReceiver != null) {
			unregisterReceiver(mReceiver);
			mReceiver = null;
		}
	}

	public int getScreenWidth() {
		return mWidth;
	}
	
	public int getScreenHeight() {
		return mHeight;
	}
}
